package com.sbl.bajw.pc.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sbl.bajw.pc.model.DeptModel;
import com.sbl.bajw.pc.service.StreetDeptService;
import com.sbl.bajw.util.JsonUtil;

@Controller
@RequestMapping("/StreetDept")
public class StreetDeptAction {
	
	@Resource
	private StreetDeptService service;
	
	@RequestMapping(value = "/getDept")
	public @ResponseBody String getDept(HttpServletRequest request, HttpServletResponse response){
		String id = request.getParameter("id");
		List<DeptModel> model = service.getDept(id);
		String result = JsonUtil.ConvertArrayToJson(model);
		return result;
	}
	
	@RequestMapping(value = "/getDeptByBound")
	public @ResponseBody String getDeptByBound(@RequestParam("pid") String pid){
		
		List<DeptModel> models = service.getOrgPid(pid);
		String result = JsonUtil.ConvertArrayToJson(models);
		return result;
	}
	
	@RequestMapping(value = "/getDeptById")
	public @ResponseBody String getDeptById(@RequestParam("id") String id){
		
		DeptModel model = service.getOrgById(id);
		String result = JsonUtil.ConvertObjectToJson(model);
		return result;
	}

	@RequestMapping(value = "/getOrgByLevel")
	public @ResponseBody String getOrgByLevel(@RequestParam(value="fullid",required=false) String fullid,
			@RequestParam(value="level",required=false) String level){
		List<DeptModel> models = service.getOrgByLevel(level, fullid);
		String result = JsonUtil.ConvertArrayToJson(models);
		return result;
	}
	
	@RequestMapping(value = "/getInitOrg")
	public @ResponseBody String getInitOrg(HttpServletRequest request, HttpServletResponse response){
		HashMap<String, Object> parm = new HashMap<String, Object>();
		String[] fullid = request.getParameter("fullid").split("-");
		parm.put("fullid", fullid);
		List<Map<String, Object>> list = service.getInitOrg(parm);
		String json = JsonUtil.ConvertArrayToJson(list);
		return json;
	}
}
